package com.lfy.kcat.workflow.controller;

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 测试流程 ap
 * @Description:
 * @Author: lfy
 * @Date: 2022/7/27 16:01
 **/
@RestController
//@RequestMapping("/process/start/{key}")

public class ProcessFunctionController {

    private final RuntimeService runtimeService;

    public ProcessFunctionController(RuntimeService runtimeService) {
        this.runtimeService = runtimeService;
    }

    @GetMapping("/vocation/process/start")
    public List<String> startProcess() {
        //已经启动了的流程才哟获取

        //启动流程实例
        ProcessInstance vocationRequest = runtimeService.startProcessInstanceByKey
            ("vocationRequest");
        //四个获取流程实例的属性：中文名、流程定义ID、业务ID、流程实例ID
        //功能：获取流程实例的属性，获取流程实例的ID、流程定义ID、业务ID、流程实例ID
        String id = vocationRequest.getId();
        String processDefinitionId = vocationRequest.getProcessDefinitionId();
        String businessKey = vocationRequest.getBusinessKey();
        String processInstanceId = vocationRequest.getProcessInstanceId();

        return Arrays.asList(id, processDefinitionId, businessKey, processInstanceId);
    }
}
